﻿Public Class FormWorkReportList
    Dim objJp As New clsJp
    Dim txt As TextBox
    Private Sub FormWorkReportList_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim startDate As String = Date.Now.ToShortDateString()
        txtStartDate.Text = startDate
        Dim endDate As String = Date.Now.ToShortDateString()
        txtEndDate.Text = endDate
        setDgvData()
    End Sub

    Private Sub btnSearch_Click(sender As Object, e As EventArgs) Handles btnSearch.Click
        setDgvData()
    End Sub

    Private Sub setDgvData()
        Dim dtJp As DataTable = objJp.getList(txtStartDate.Text & " 00:00:00.000", txtEndDate.Text & " 23:59:59.999", txt_material_code.Text.Trim())
        dtJp.Columns.Add("mes_sync_status_name")
        If dtJp.Rows.Count > 0 Then
            For Each row As DataRow In dtJp.Rows
                If row("mes_sync_status") = "0" Then
                    row("mes_sync_status_name") = "未同步"
                End If
                If row("mes_sync_status") = "01" Then
                    row("mes_sync_status_name") = "报工失败"
                End If
                If row("mes_sync_status") = "1" Then
                    row("mes_sync_status_name") = "报工成功"
                End If
                If row("mes_sync_status") = "02" Then
                    row("mes_sync_status_name") = "入库失败"
                End If
                If row("mes_sync_status") = "2" Then
                    row("mes_sync_status_name") = "入库成功"
                End If
            Next
        End If
        dgv.AutoGenerateColumns = False
        dgv.DataSource = dtJp
        lblCount.Text = dgv.Rows.Count
    End Sub

    Private Sub txt_MouseClick(sender As Object, e As MouseEventArgs) Handles txtStartDate.MouseClick, txtEndDate.MouseClick
        txt = CType(sender, TextBox)
        DateNavigator1.Left = txt.Left
        DateNavigator1.Top = txt.Location.Y + txt.Height
        DateNavigator1.Visible = True
    End Sub

    Private Sub DateNavigator1_DateTimeChanged(sender As Object, e As EventArgs) Handles DateNavigator1.DateTimeChanged
        txt.Text = DateNavigator1.DateTime.ToShortDateString()
        DateNavigator1.Visible = False
    End Sub

    Private Sub btnDelete_Click(sender As Object, e As EventArgs) Handles btnDelete.Click
        If dgv.SelectedRows.Count > 0 Then
            If MsgBox("确认要删除此生产完工记录吗？", vbYesNo, "提示") = vbYes Then
                Dim rtn As Integer = objJp.del(dgv.SelectedRows(0).Cells("sys_id").Value.ToString())
                If rtn <> -2 Then
                    MsgBox("删除成功", vbYes, "提示")
                    setDgvData()
                Else
                    MsgBox("删除失败", vbYes, "提示")
                End If
            End If
        Else
            MsgBox("请选择需要删除的记录", vbYes, "提示")
        End If

    End Sub
End Class